<?php
class Aprops {
	public static function main($funcode) {
		sview::verify(true, true);
		switch ($funcode) {
			case 1:
				self::__doprops();
				break;
			case 2:
				self::__dodelete();
				break;
			case 3:
				self::__domotor();
				break;
			case 4:
				self::__dogifts();
				break;
			case 5:
				self::__dogiftsend();
				break;
			default:
				sview::$view->assign_error(404, lang::text(404));
		}
	}
	
	//我的道具列表 3-9-1
	private static function __doprops() {
		$start  = intval(sview::$ctrl['offset']);
		$limit  = intval(sview::$ctrl['limit']);
		$acl    = acl::getinst('vedio');
		$userid = $acl->user['id'];
		$expire = isset(sview::$ctrl['isexpire'])? intval(sview::$ctrl['isexpire']):0;
		$rtype  = isset(sview::$ctrl['reftype'])? intval(sview::$ctrl['reftype']):0;
		$data   = api_mypros::dolist($userid, $rtype, $expire, $start, $limit);
		sview::$view->assign_by_ref('datasets', $data);
		sview::$view->display();
	}
	
	//删除过期的道具信息记录 3-9-2
	private static function __dodelete() {
		$acl   = acl::getinst('vedio');
		$userid= $acl->user['id'];
		$ids   = trim(sview::$ctrl['ids']);
		api_mypros::dodelete($userid, $ids);
		sview::$view->display();
	}
	
	//穿戴变更座驾信息 3-9-3
	private static function __domotor() {
		$acl   = acl::getinst('vedio');
		$userid= $acl->user['id'];
		$motorid= (int)sview::$ctrl['id'];
		api_mypros::domotor(sview::$view, $userid, $motorid);
		sview::$view->display();
	}
	
	//获取背包礼物 3-9-4
	private static function __dogifts() {
		$acl    = acl::getinst('vedio');
		$userid = $acl->user['id'];
		$list   = api_mygift::dolist($userid);
		sview::$view->assign('datasets', $list);
		sview::$view->display();
	}
	
	//赠送背包礼物 3-9-5
	private static function __dogiftsend() {
		$acl    = acl::getinst('vedio');
		$userid = $acl->user['id'];
		//礼物id和直播ID编号
		$sid    = isset(sview::$ctrl['sid'])? intval(sview::$ctrl['sid']):0;
		$nums   = isset(sview::$ctrl['nums'])? intval(sview::$ctrl['nums']):1;
		$giftid = isset(sview::$ctrl['giftid'])? intval(sview::$ctrl['giftid']):0;
		($nums < 1) && $nums = 1;
		$last   = api_mygift::dosend(sview::$view, $userid, $giftid, $nums, $sid);
		$dataset= array('giftid'=>$giftid, 'last'=>$last, 'nums'=>$nums);
		sview::$view->assign_by_ref('datasets', $dataset);
		sview::$view->display();
		api_mygift::dosendhooks($userid, $sid, $giftid, $nums);
	}
}